<html>
<head><meta charset="utf-8"><title>Custom inner attribute · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Custom.20inner.20attribute.html">Custom inner attribute</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="242636827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Custom%20inner%20attribute/near/242636827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jerry Liu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Custom.20inner.20attribute.html#242636827">(Jun 14 2021 at 18:01)</a>:</h4>
<p>Hi all! I wonder if there's a way to define our own inner attribute like <code>#![attr_name]</code> and then later I can process the input tokenstream just like a normal procedure macro attribute? I have visited this tracking issue and would like to know any updates related to this feature: <a href="https://github.com/rust-lang/rust/issues/54726">https://github.com/rust-lang/rust/issues/54726</a></p>



<a name="242639403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Custom%20inner%20attribute/near/242639403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Custom.20inner.20attribute.html#242639403">(Jun 14 2021 at 18:21)</a>:</h4>
<p>You should be able to use it on nightly without encountering many problems</p>



<a name="242639499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Custom%20inner%20attribute/near/242639499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Custom.20inner.20attribute.html#242639499">(Jun 14 2021 at 18:22)</a>:</h4>
<p>If you're wondering about stabilization - there was some discussion about the proper handling of resolution. I don't know if petrochenkov's decision was implemented</p>



<a name="242639643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Custom%20inner%20attribute/near/242639643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Custom.20inner.20attribute.html#242639643">(Jun 14 2021 at 18:24)</a>:</h4>
<p>Once the resolution issue is resolved (lol), I think we could stabilize custom inner attributes in most positions</p>



<a name="242639748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Custom%20inner%20attribute/near/242639748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Custom.20inner.20attribute.html#242639748">(Jun 14 2021 at 18:24)</a>:</h4>
<p>Attributes at the crate/module root are not yet ready to be stabilized, since we don't yet capture tokens correctly there</p>



<a name="243425259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Custom%20inner%20attribute/near/243425259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jerry Liu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Custom.20inner.20attribute.html#243425259">(Jun 21 2021 at 18:41)</a>:</h4>
<p>Thanks for the help, so what should we do if we want to process the whole crate's tokenstream? (what I think is to define the inner attribute at crate root) Should we wait and do the ast visit?</p>



<a name="243425505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Custom%20inner%20attribute/near/243425505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jerry Liu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Custom.20inner.20attribute.html#243425505">(Jun 21 2021 at 18:43)</a>:</h4>
<p>Also, can you give me a pointer for how to define the our own custom inner attribute? I only see the outer attribute in <code>#[proc_macro_attribute]</code></p>



<a name="243426315"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Custom%20inner%20attribute/near/243426315" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Custom.20inner.20attribute.html#243426315">(Jun 21 2021 at 18:49)</a>:</h4>
<p><span class="user-mention" data-user-id="410549">@Jerry Liu</span> Outer and inner attributes both work with <code>#[proc_macro_attribute]</code>.</p>



<a name="243426479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Custom%20inner%20attribute/near/243426479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jerry Liu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Custom.20inner.20attribute.html#243426479">(Jun 21 2021 at 18:51)</a>:</h4>
<p>Thanks a lot, didn't notice that earlier</p>



<a name="243428658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Custom%20inner%20attribute/near/243428658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jerry Liu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Custom.20inner.20attribute.html#243428658">(Jun 21 2021 at 19:08)</a>:</h4>
<p>I've tried creating the inner_attribute by <code>#[proc_macro_attribute]</code>, however if I put it at the root then the compiler has trouble to do the resolution (this looks reasonable since the function to process the attribute is in another crate), but inner attribute is not permitted after I declare the crate I want to use. Is there anyway to define the inner attribute and export it to be used in another crate?</p>



<a name="243430162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Custom%20inner%20attribute/near/243430162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Custom.20inner.20attribute.html#243430162">(Jun 21 2021 at 19:21)</a>:</h4>
<p>You don't need extern crate in the <del>2021</del> 2018 edition.</p>



<a name="243431110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Custom%20inner%20attribute/near/243431110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jerry Liu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Custom.20inner.20attribute.html#243431110">(Jun 21 2021 at 19:29)</a>:</h4>
<p>Sorry if I am not being clear, let me put up an example here:<br>
<a href="/user_uploads/4715/lM4k9VUXNxbIDSyJfSCNZEbB/image.png">image.png</a> <br>
What i try to do is to define the custom inner attribute in prusti_contract crate, but this attribute needs to be reused in another crate. </p>
<div class="message_inline_image"><a href="/user_uploads/4715/lM4k9VUXNxbIDSyJfSCNZEbB/image.png" title="image.png"><img src="/user_uploads/4715/lM4k9VUXNxbIDSyJfSCNZEbB/image.png"></a></div><p>If I have inner attribute there, I got: <a href="/user_uploads/4715/iigVyYdzHUo5GjbjOJZMZcdg/image.png">image.png</a> </p>
<div class="message_inline_image"><a href="/user_uploads/4715/iigVyYdzHUo5GjbjOJZMZcdg/image.png" title="image.png"><img src="/user_uploads/4715/iigVyYdzHUo5GjbjOJZMZcdg/image.png"></a></div><p>If I move the attribute to somewhere before I import the prusti_contract crate, the compiler cannot do the resolution of the inner attribute</p>



<a name="243431260"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Custom%20inner%20attribute/near/243431260" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Custom.20inner.20attribute.html#243431260">(Jun 21 2021 at 19:30)</a>:</h4>
<p>Try <code>#![prusti_contracts::export_all]</code> above the extern crate. Also if you are using the 2018 edition, the extern crate is unnecessary.</p>



<a name="243431502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Custom%20inner%20attribute/near/243431502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jerry Liu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Custom.20inner.20attribute.html#243431502">(Jun 21 2021 at 19:32)</a>:</h4>
<p>Gotcha! Looks like it's working! Thanks</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>